.chat-detail-container {
  width: 100%;
  height: 100vh;
  background-color: #f5f5f5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  min-height: 0; /* 重要：确保flex子元素能正确收缩 */
  position: relative;
}

/* 聊天记录区域 */
.chat-messages {
  flex: 1;
  padding: 20rpx;
  padding-bottom: 400rpx; /* 为底部快捷回复(约100rpx)和输入区域(约260rpx)以及消息时间戳(约40rpx)留出足够空间 */
  background-color: #f5f5f5;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  /* 确保scroll-view有明确的高度 */
}

.message-item {
  margin-bottom: 30rpx;
  width: 100%;
  min-height: 60rpx;
  display: block;
  
  &.user-message {
    .message-wrapper {
      display: flex !important;
      align-items: flex-start;
      width: 100%;
      min-height: 60rpx;
      
      .message-avatar {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 20rpx;
        flex-shrink: 0;
        background: #f0f0f0;
        transition: opacity 0.2s;
        cursor: pointer;
        
        image {
          width: 100%;
          height: 100%;
        }

        &:active {
          opacity: 0.7;
        }
      }
      
      .message-content-wrapper {
        flex: 1;
        min-width: 0;
        
        .message-header {
          display: flex;
          align-items: center;
          margin-bottom: 10rpx;
          
          .sender-name {
            font-size: 24rpx;
            color: #666;
            margin-right: 15rpx;
          }
          
          .message-time {
            font-size: 22rpx;
            color: #999;
          }
        }
        
        .user-bubble {
          background: white;
          border-radius: 16rpx 16rpx 16rpx 4rpx;
          padding: 20rpx 24rpx;
          box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
          
          .message-text {
            font-size: 28rpx;
            color: #333;
            line-height: 1.5;
            word-break: break-word;
          }
        }
      }
    }
  }
  
  &.merchant-message {
    .merchant-wrapper {
      display: flex !important;
      justify-content: flex-end;
      align-items: flex-start;
      width: 100%;
      min-height: 60rpx;
      
      .message-content-wrapper {
        max-width: 70%;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: flex-end;
        gap: 15rpx;
        
        .message-bubble-container {
          display: flex;
          flex-direction: column;
          align-items: flex-end;
          flex: 1;
          min-width: 0;
        }
        
        .merchant-avatar {
          width: 60rpx;
          height: 60rpx;
          border-radius: 50%;
          overflow: hidden;
          flex-shrink: 0;
          background: #f0f0f0;
          transition: opacity 0.2s;
          
          image {
            width: 100%;
            height: 100%;
          }

          &:active {
            opacity: 0.7;
          }
        }
        
        .merchant-coupon-card {
          width: 100%;
          box-sizing: border-box;
          background: linear-gradient(135deg, #1976d2 0%, #42a5f5 100%);
          box-shadow: 0 4rpx 12rpx rgba(25, 118, 210, 0.25);
          
          .coupon-amount .amount-value {
            font-size: 52rpx;
          }
        }

        .merchant-bubble {
          background: #5cb85c;
          border-radius: 16rpx 16rpx 4rpx 16rpx;
          padding: 20rpx 24rpx;
          box-shadow: 0 2rpx 8rpx rgba(92, 184, 92, 0.2);
          max-width: 100%;
          
          .message-text {
            font-size: 28rpx;
            color: white;
            line-height: 1.5;
            word-break: break-word;
          }
        }
        
        .message-time {
          font-size: 22rpx;
          color: #999;
          margin-top: 10rpx;
          text-align: right;
        }
      }
    }
  }
  
  &.system-message {
    .system-wrapper {
      display: flex !important;
      justify-content: center;
      width: 100%;
      min-height: 60rpx;
      
      .message-content-wrapper {
        max-width: 80%;
        
        .message-header {
          display: flex;
          align-items: center;
          justify-content: center;
          margin-bottom: 10rpx;
          
          .sender-name {
            font-size: 24rpx;
            color: #999;
            margin-right: 15rpx;
          }
          
          .message-time {
            font-size: 22rpx;
            color: #999;
          }
        }
        
        .system-bubble {
          background: #f0f0f0;
          border-radius: 16rpx;
          padding: 20rpx 24rpx;
          
          .message-text {
            font-size: 26rpx;
            color: #666;
            line-height: 1.5;
            word-break: break-word;
          }
        }
      }
    }
  }
}

/* 优惠券卡片 */
.coupon-card {
  background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(255, 107, 107, 0.3);
  
  .coupon-header {
    margin-bottom: 20rpx;
    
    .coupon-title {
      font-size: 28rpx;
      color: white;
      font-weight: 600;
    }
  }
  
  .coupon-body {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .coupon-amount {
      display: flex;
      align-items: baseline;
      margin-right: 30rpx;
      
      .amount-symbol {
        font-size: 32rpx;
        color: white;
        font-weight: 600;
      }
      
      .amount-value {
        font-size: 56rpx;
        color: white;
        font-weight: bold;
        line-height: 1;
      }
    }
    
    .coupon-info {
      flex: 1;
      display: flex;
      flex-direction: column;
      
      .coupon-condition {
        font-size: 24rpx;
        color: rgba(255, 255, 255, 0.9);
        margin-bottom: 8rpx;
      }
      
      .coupon-expire {
        font-size: 22rpx;
        color: rgba(255, 255, 255, 0.8);
      }
    }
  }
  
  .coupon-footer {
    padding-top: 20rpx;
    border-top: 1rpx solid rgba(255, 255, 255, 0.3);
    
    .coupon-message {
      font-size: 24rpx;
      color: rgba(255, 255, 255, 0.9);
      line-height: 1.5;
    }
  }
}

/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 60rpx;
  text-align: center;
  min-height: 400rpx;
  
  .empty-icon {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 30rpx;
    opacity: 0.3;
  }
  
  .empty-text {
    font-size: 28rpx;
    color: #999;
  }
}

/* 加载状态 */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 100rpx 60rpx;
  min-height: 400rpx;
  
  .loading-text {
    font-size: 28rpx;
    color: #999;
  }
}

/* 快捷回复 */
.quick-replies {
  padding: 20rpx;
  background: white;
  border-top: 1rpx solid #f0f0f0;
  flex-shrink: 0;
  position: fixed;
  bottom: 260rpx; /* 在输入区域上方，输入区域高度：80(输入框) + 15(gap) + 70(按钮) + 40(上下padding) + 安全区域 ≈ 260rpx */
  left: 0;
  right: 0;
  z-index: 1001; /* 比输入区域高，确保不被遮挡 */
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  max-height: 100rpx; /* 限制最大高度，避免遮挡消息 */
  
  .quick-scroll {
    white-space: nowrap;
    
    .quick-btn {
      display: inline-block;
      padding: 12rpx 24rpx;
      margin-right: 15rpx;
      background: #f8f9fa;
      border: 1rpx solid #e9ecef;
      border-radius: 30rpx;
      font-size: 24rpx;
      color: #666;
      
      &:active {
        background: #e9ecef;
      }
    }
  }
}

/* 输入区域 */
.chat-input-area {
  padding: 20rpx;
  padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  background: white;
  border-top: 1rpx solid #f0f0f0;
  display: flex !important;
  flex-direction: column !important;
  gap: 15rpx;
  box-sizing: border-box;
  position: fixed !important;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  flex-shrink: 0;
  width: 100%;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  
  .input-row {
    width: 100%;
    display: flex;
    align-items: center;
  }
  
  .message-input {
    width: 100% !important;
    padding: 20rpx 24rpx !important;
    background: #f8f9fa !important;
    border-radius: 30rpx !important;
    font-size: 28rpx !important;
    color: #333 !important;
    box-sizing: border-box !important;
    min-height: 80rpx !important;
    line-height: 40rpx !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    border: 2rpx solid #d0d0d0 !important;
  }
  
  .input-actions {
    display: flex;
    gap: 15rpx;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    
    .send-coupon-btn {
      flex: 0 0 auto;
      padding: 18rpx 32rpx;
      background: #ff9800;
      color: white;
      border-radius: 25rpx;
      font-size: 26rpx;
      border: none;
      min-width: 120rpx;
      height: 70rpx;
      line-height: 34rpx;
      white-space: nowrap;
      
      &::after {
        border: none;
      }
      
      &:active {
        background: #f57c00;
      }
    }
    
    .send-message-btn {
      flex: 0 0 auto;
      padding: 18rpx 32rpx;
      background: #5cb85c;
      color: white;
      border-radius: 25rpx;
      font-size: 26rpx;
      border: none;
      min-width: 120rpx;
      height: 70rpx;
      line-height: 34rpx;
      white-space: nowrap;
      
      &::after {
        border: none;
      }
      
      &:disabled {
        background: #ccc;
        color: #999;
      }
      
      &:active:not(:disabled) {
        background: #4cae4c;
      }
    }
  }
}

/* 优惠券弹窗 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000; /* 远高于其他元素，确保弹窗在最上层 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40rpx;
}

.coupon-modal {
  background: white;
  border-radius: 20rpx;
  width: 100%;
  max-width: 600rpx;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10001; /* 确保弹窗内容在遮罩层之上 */
  
  .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30rpx;
    border-bottom: 1rpx solid #f0f0f0;
    
    .modal-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
    }
    
    .modal-close {
      font-size: 48rpx;
      color: #999;
      line-height: 1;
      padding: 10rpx;
    }
  }
  
  .modal-body {
    flex: 1;
    padding: 30rpx;
    padding-bottom: 40rpx; /* 增加底部padding，确保自定义消息输入框不被遮挡 */
    overflow-y: auto;
    min-height: 0; /* 确保flex子元素能正确收缩 */
    max-height: calc(80vh - 200rpx); /* 减去header和footer的高度 */
    
    .coupon-list {
      margin-bottom: 30rpx;
      
      .coupon-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 25rpx;
        background: #f8f9fa;
        border-radius: 12rpx;
        margin-bottom: 15rpx;
        border: 2rpx solid transparent;
        
        &:active {
          background: #e9ecef;
        }
        
        .coupon-info {
          flex: 1;
          
          .coupon-name {
            display: block;
            font-size: 28rpx;
            font-weight: 600;
            color: #333;
            margin-bottom: 8rpx;
          }
          
          .coupon-desc {
            display: block;
            font-size: 24rpx;
            color: #666;
            margin-bottom: 8rpx;
          }
          
          .coupon-validity {
            display: block;
            font-size: 22rpx;
            color: #999;
          }
        }
        
        .coupon-value {
          .coupon-amount {
            font-size: 32rpx;
            font-weight: bold;
            color: #5cb85c;
          }
        }
      }
    }
    
    .custom-message-input {
      margin-top: 20rpx;
      padding-top: 20rpx;
      border-top: 1rpx solid #f0f0f0;
      
      .input-label {
        display: block;
        font-size: 26rpx;
        color: #666;
        margin-bottom: 15rpx;
      }
      
      .custom-input {
        width: 100%;
        padding: 20rpx;
        background: #f8f9fa;
        border-radius: 12rpx;
        font-size: 28rpx;
        color: #333;
        box-sizing: border-box;
        border: 1rpx solid #e0e0e0;
        min-height: 80rpx;
      }
    }
  }
  
  .modal-footer {
    display: flex;
    gap: 20rpx;
    padding: 30rpx;
    border-top: 1rpx solid #f0f0f0;
    flex-shrink: 0; /* 确保footer不被压缩 */
    
    .cancel-btn {
      flex: 1;
      padding: 25rpx;
      background: #f5f5f5;
      color: #666;
      border-radius: 12rpx;
      font-size: 30rpx;
      border: none;
      
      &::after {
        border: none;
      }
    }
    
    .confirm-btn {
      flex: 1;
      padding: 25rpx;
      background: #5cb85c;
      color: white;
      border-radius: 12rpx;
      font-size: 30rpx;
      border: none;
      
      &::after {
        border: none;
      }
      
      &:disabled {
        background: #ccc;
      }
    }
  }
}

